package lianxi;

public class _08_ {

	public static void main(String[] args) {
		String[] arr = { "12", "2", "45", "5" };
		sort(arr);
		for (String string : arr) {
			System.out.print(string + "  ");
		}
	}

	/**
	 * 冒泡排序方法
	 * 
	 * @param arr
	 */
	public static void sort(String arr[]) {
		int[] arr1 = new int[arr.length];
		String s = null;
		// 字符串数组转整数数组
		for (int i = 0; i < arr.length; i++) {
			s = arr[i];
			arr1[i] = Integer.parseInt(s);
		}
		// 冒泡排序
		for (int i = 0; i < arr1.length-1; i++) {
			for (int j = 0; j < arr1.length-i-1; j++) {
				if (arr1[j] < arr1[j+1]) {
					// 交换元素位置
					arr1[j] += arr1[j+1];
					arr1[j+1] = arr1[j] - arr1[j+1];
					arr1[j] = arr1[j] - arr1[j+1];
				}
			}
		}
		// 整型数组转字符串数组
		for (int i = 0; i < arr1.length; i++) {
			s = arr1[i] + "";
			arr[i] = s;
		}
	}
}
